package com.xpqh.ksg.modular.users.controller;

import com.xpqh.ksg.base.BaseController;
import com.xpqh.ksg.base.BaseResponseDTO;
import com.xpqh.ksg.common.enums.result.BizExceptionEnum;
import com.xpqh.ksg.common.persistence.model.KsgUsers;
import com.xpqh.ksg.common.utils.JwtTokenUtil;
import com.xpqh.ksg.modular.users.dto.KsgUserUpdateReqDTO;
import com.xpqh.ksg.modular.users.service.KsgUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/ksg/users")
public class KsgUsersController extends BaseController {

    @Autowired
    private KsgUsersService ksgUsersService;

    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    @GetMapping("/get")
    public BaseResponseDTO get(){
        KsgUsers KsgUsers = ksgUsersService.get(getUserId());
        return renderResultOk(KsgUsers);
    }

    @PostMapping("/update/info")
    public BaseResponseDTO updateInfo(@Valid @RequestBody KsgUserUpdateReqDTO reqDTO) {
        boolean isSuccess = ksgUsersService.updateUserInfo(reqDTO, getUserId());
        if (isSuccess) {
            return renderResultOk();
        } else {
            return renderResult(BizExceptionEnum.USER_NOT_FOUND);
        }
    }
}


